label: Update layout width directly form allocation
authorTimm Bäder <mail@baedert.org>
Wed, 17 Jan 2018 11:36:37 +0000 (12:36 +0100)
committerTimm Bäder <mail@baedert.org>
Wed, 17 Jan 2018 20:57:19 +0000 (21:57 +0100)
For the one update_layout_width call in size_allocate, we can just use
the passed-in allocation width instead of a separate (relatively slow)
gtk_widget_get_width call.

gtk/gtklabel.c

index 8df6e8f018e5bc8e12e5dcbbfe90a6b303c117a6..cd969492f688d32d3ae065a94a0589f82689ee63 100644 (file)
@@ -3304,19 +3304,6 @@ gtk_label_get_measuring_layout (GtkLabel *   label,
   return copy;
 }
 
-static void
-gtk_label_update_layout_width (GtkLabel *label)
-{
-  GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
-
-  g_assert (priv->layout);
-
-  if (priv->ellipsize || priv->wrap)
-    pango_layout_set_width (priv->layout, gtk_widget_get_width (GTK_WIDGET (label)) * PANGO_SCALE);
-  else
-    pango_layout_set_width (priv->layout, -1);
-}
-
 static void
 gtk_label_update_layout_attributes (GtkLabel *label)
 {
@@ -3424,7 +3411,8 @@ gtk_label_ensure_layout (GtkLabel *label)
       if (priv->lines > 0)
         pango_layout_set_height (priv->layout, - priv->lines);
 
-      gtk_label_update_layout_width (label);
+      if (priv->ellipsize || priv->wrap)
+        pango_layout_set_width (priv->layout, gtk_widget_get_width (GTK_WIDGET (label)) * PANGO_SCALE);
     }
 }
 
@@ -3736,7 +3724,13 @@ gtk_label_size_allocate (GtkWidget           *widget,
   GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
 
   if (priv->layout)
-    gtk_label_update_layout_width (label);
+    {
+      if (priv->ellipsize || priv->wrap)
+        pango_layout_set_width (priv->layout,
+                                allocation->width * PANGO_SCALE);
+      else
+        pango_layout_set_width (priv->layout, -1);
+    }
 
   gtk_label_get_ink_rect (label, out_clip);
 }